package com.shouhuobao.bhi.share;

import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.os.Bundle;
import android.view.Gravity;
import android.view.View;
import android.view.ViewGroup;
import android.view.Window;
import android.view.WindowManager;

import com.collectplus.express.BaseActivity2;
import com.collectplus.express.R;
import com.collectplus.express.wxapi.WXshare;

/**
 * Created by joker on 2017/11/28.
 * 用于活动h5的分享跳转
 */
public class ActiveShareActivity extends BaseActivity2 implements View.OnClickListener {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        // 第二个方法在此参数无效
        super.onCreate(savedInstanceState);
        overridePendingTransition(R.anim.in_bottom2top, 0);
        Window win = getWindow();
        win.getDecorView().setPadding(0, 0, 0, 0);
        // win.getDecorView().setMinimumWidth((int) (win.getWindowManager().getDefaultDisplay().getWidth() * 0.6));// 设置dialog的宽度
        WindowManager.LayoutParams lp = win.getAttributes();
        lp.width = ViewGroup.LayoutParams.MATCH_PARENT;
        lp.height = ViewGroup.LayoutParams.WRAP_CONTENT;
        // lp.horizontalMargin = 300;
        lp.gravity = Gravity.BOTTOM;
        win.setAttributes(lp);

    }

    @Override
    protected void findViewById() {
        setContentView(R.layout.activity_active_share);
        super.findViewById();
        findViewById(R.id.share_wx_tv).setOnClickListener(this);
        findViewById(R.id.share_wx_friendcircle_tv).setOnClickListener(this);
        findViewById(R.id.cancel_bt).setOnClickListener(this);
    }

    @Override
    public void onClick(View v) {
        switch (v.getId()) {
            //分享微信好友
            case R.id.share_wx_tv:
                shareToWX(0);
                break;
            //分享到微信朋友圈
            case R.id.share_wx_friendcircle_tv:
                shareToWX(1);
                break;
            //取消分享
            case R.id.cancel_bt:
                finish();
                break;
        }
    }

    /**
     * @param type 0 好友  1朋友圈
     */
    private void shareToWX(int type) {
        WXshare mWXshare = new WXshare(getContext());
        String shareUrl = "";
        String shareTitle = "我在参加火箭投递0元寄快递助力活动，马上成功了！快来帮我助力一下";
        String shareDescription = "帮他助力你也可得火箭投递邮票哦！快来给他助力吧！";
        Bitmap shareThumb = BitmapFactory.decodeResource(getResources(), R.drawable.active_share);
        mWXshare.shareWX(type, shareTitle, shareDescription, shareThumb, shareUrl, null, null);
    }

    @Override
    public void finish() {
        super.finish();
        overridePendingTransition(0, R.anim.out_top2bottom);
    }

    @Override
    protected void onDestroy() {
        super.onDestroy();
    }

}
